<template>
    <section>
    </section>
</template>

<script>
    export default {
        name: "loginBack",
        data(){
          return{

          }
        },
      created(){

        this.$dialog.loading.open('登录中');
        function getParams(url) {

          var theRequest = new Object();
          if (!url)
            url = location.href;
          if (url.indexOf("?") !== -1) {
            var str = url.substr(url.indexOf("?") + 1) + "&";
            var strs = str.split("&");
            for (var i = 0; i < strs.length - 1; i++) {
              var key = strs[i].substring(0, strs[i].indexOf("="));
              var val = strs[i].substring(strs[i].indexOf("=") + 1);
              theRequest[key] = val;
            }
          }
          return theRequest;
        }
        const code =  getParams().code;
        const state = getParams().state;
        const that = this;
        setTimeout(()=>{
          that.$ajax.post(window.g.apiUrl+'/user/wechatpub.do',JSON.stringify({
          code:code,
        })).then((response)=>{
          that.$dialog.loading.close();
            if(response.data.code == 200){
              let redirectUrl = JSON.parse(sessionStorage.getItem('redirectUrl'));
              redirectUrl != null ? that.$router.replace(redirectUrl.url):that.$router.replace('/index');
            }else{
              that.$dialog.notify({
                mes: '登录失败',
                timeout: 1500,
                callback:()=>{
                  that.$router.replace('/login')
                }
              });
            }
          }).catch(()=>{
        })
        },100)
      }
    }
</script>

<style scoped>

</style>
